#include "headfiles.h"

using namespace std;

int main(int argc, char **argv) {
    if (argc != 3) {
        cout << "Usage: " << argv[0] << "file num" << endl;
        return 0;
    }

    string file_name(argv[1]);
    int sum = atoi(argv[2]);

    ifstream fs;
    fs.open(file_name.c_str(), fstream::in);
    if (!fs.is_open()) {
        cout << "File " << file_name << " open error!" << endl;
        return 1;
    }

    int elem_num;
    string str;

    fs >> str;
    elem_num = atoi(str.c_str());
    if (elem_num <= 0) {
        cout << "Number of elems is invalid," << elem_num << ", error!" << endl;
        return 1;
    }

    int *array = (int *)malloc(sizeof(int) * elem_num);
    if (array == NULL) {
        cout << "Allocate array error, NULL!" << endl;
        return 1;
    }

    int index = 0;
    while (fs >> str) {
        if (str.empty()) {
            break;
        }

        array[index++] = atoi(str.c_str());
    }

    if (index != elem_num) {
        cout << "Incorrect number of elems" << endl;
        return 1;
    }

    bool ret;
    cout << "Method 1 result:" << endl;
    ret = findIntPairs(array, elem_num, sum);

    cout << "Method 2 result:" << endl;
    ret = findIntPairs1(array, elem_num, sum);

    free(array);

    return 0;
}



